<template>
  <div class="app-container">
    <div class="filter-container">
      <el-row>
        <el-col class="filter-column" :lg="8" :sm="12">
          <el-date-picker
            v-model="listQuery.date"
            type="daterange"
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          >
          </el-date-picker>
        </el-col>
        <el-col class="filter-column" :lg="8" :sm="12">
          <el-input
            placeholder="请输入操作者"
            v-model="listQuery.name"
            style="width: 170px"
            clearable
            @keyup.enter.native="handleFilter"
          />
          <el-input
            placeholder="请输入访问接口"
            v-model="listQuery.content"
            style="width: 170px"
            clearable
            @keyup.enter.native="handleFilter"
          />
        </el-col>
        <el-col class="filter-column" :lg="8" :sm="24">
          <el-input
            placeholder="请输入参数内容"
            v-model="listQuery.sql_record"
            style="width: 170px"
            clearable
            @keyup.enter.native="handleFilter"
          />
          <el-button type="primary" icon="el-icon-search" @click="handleFilter"
            >查询</el-button
          >
        </el-col>
      </el-row>
    </div>
    <div class="table-container">
      <el-table
        v-loading="listLoading"
        :key="tableKey"
        :data="list"
        border
        fit
        @sort-change="sortHanlde"
        highlight-current-row
        style="width: 100%"
      >
        <el-table-column
          label="序号"
          prop="id"
          sortable="custom"
          align="left"
          width="105"
        >
        </el-table-column>
        <el-table-column
          label="操作者"
          prop="name"
          sortable="custom"
          width="120px"
          align="left"
        >
        </el-table-column>
        <el-table-column
          label="访问接口"
          prop="content"
          sortable="custom"
          width="200px"
          align="left"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          label="参数内容"
          prop="sql_record"
          sortable="custom"
          width="200px"
          align="left"
        >
          <template slot-scope="scope">
            <el-popover placement="right" width="400" trigger="hover">
              <span>{{ scope.row.sql_record }}</span>
              <input
                type="text"
                readonly
                slot="reference"
                class="input-text-overflow"
                style="width: 96%"
                v-model="scope.row.sql_record"
              />
              <!-- <el-button type="text" slot="reference">详情>></el-button> -->
            </el-popover>
          </template>
        </el-table-column>
        <el-table-column
          label="操作时间"
          prop="create_time"
          sortable="custom"
          width="140px"
          align="left"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          label="操作"
          align="left"
          width="100"
          class-name="small-padding fixed-width"
        >
          <template slot-scope="scope">
            <el-button type="primary" size="mini" @click="showLog(scope.row)"
              >查看</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="listQuery.page"
        :limit.sync="listQuery.limit"
        @pagination="pageHandle"
      />
    </div>
    <div class="dialog-container">
      <!-- 角色编辑弹框 -->
      <logShowctl :show.sync="logShow.show" :data="logShow.data"> </logShowctl>
    </div>
  </div>
</template>

<script>
import { getlist } from "@/api/adm_log";
import Pagination from "@/components/Pagination"; // Secondary package based on el-pagination
import logShowctl from "./components/logShow";
import g from "@/utils/utilFn";

export default {
  name: "rolesManage",
  components: { Pagination, logShowctl },
  data() {
    return {
      tableKey: 0,
      list: null,
      total: 0,
      listLoading: true,
      listQuery: {
        date: [],
        start: "",
        end: "",
        name: "",
        content: "",
        sql_record: "",
        page: 1,
        limit: 10,
        filed: "id",
        sort: "descending",
      },
      logShow: {
        show: false,
        data: undefined,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    getList() {
      console.log(this.listQuery);
      this.listLoading = true;
      this.listQuery.start =
        (this.listQuery.date &&
          this.listQuery.date[0] &&
          g.format(this.listQuery.date[0], "yyyy-MM-dd")) ||
        "";
      this.listQuery.end =
        (this.listQuery.date &&
          this.listQuery.date[1] &&
          g.format(this.listQuery.date[1], "yyyy-MM-dd")) ||
        "";
      getlist(this.listQuery).then((response) => {
        this.list = response.data;
        this.total = response.count || 0;
        setTimeout(() => {
          this.listLoading = false;
        }, 500);
      });
    },
    handleFilter() {
      this.getList();
    },
    sortHanlde(column) {
      console.log(column);
      this.listQuery.filed = column.prop;
      this.listQuery.sort = column.order;
      this.getList();
    },
    pageHandle(page) {
      this.listQuery.page = page.page;
      this.listQuery.limit = page.limit;
      this.getList();
    },
    showLog(row) {
      this.logShow.show = true;
      this.logShow.data = row;
    },
  },
};
</script>
